<?php

namespace App\Http\Controllers\Admin;

use App\Model\Comment;
use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;

class CommentController extends Controller
{
    /**
     * @return mixed
     * 评论列表
     */
    public function index(){
        $comment = new Comment();
        $commentInfo = $comment->orderBy('reply_status','asc')->get();
        return view('admin.comment.index',['commentInfo' => $commentInfo]);
    }

    /**
     * @param Request $request
     * 回复消息
     */
    public function reply(Request $request){
        $comment = new Comment();
        $id = $request->input("id");
        $reply = $request->input("message");
        $res = $comment->where('id',$id)->update(['reply'=>$reply]);
        if($res){
            echo 1;
        }else{
            echo 0;
        }
    }

    /**
     * @param Request $request
     * 异步修改评论状态
     */
    public function changeCommentStatus(Request $request){
        $comment = new Comment();
        $id = $request->input("comment_id");
        $status = $request->input("status");
        $res = $comment->where('id',$id)->update(['status'=>$status]);
        if($res){
            echo 1;
        }else{
            echo 0;
        }
    }
}
